#
# File: djt_sign_in.py
# Description: Django tests for account sign_in
#
# Copyright 2013 Adam Meadows
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

from django.test import TestCase

from accounts.handlers import HomeHandler

class SignInTest(TestCase):
    '''Test for signing in'''

    def test_get(self):
        '''GET should return not found'''
        r = self.client.get('/accounts/login')
        self.assertEqual(r.status_code, 404, "Get is not found")

    def test_invalid(self):
        '''Make sure error message is returned'''
        r = self.client.post(
            '/accounts/login',
            data=dict(username='foo', password='bar'),
            )

        self.assertEqual(r.status_code, 302, "Redirect given")
        self.assertEqual(r['Location'], 'http://testserver/', "Redirect to /")
        self.assertEqual(
            str(r.cookies[HomeHandler.ERROR_COOKIE]),
            'Set-Cookie: error_msg="Invalid Email/Password"; Path=/',
            'Error cookie set'
            )

